#include "DataStructure/Input/Constraint/RRODData.h"

#include "DataStructure/Common/Validation.h"
#include "DataStructure/Input/Solver/DOFDirections.h"

using namespace SG::DataStructure;
using namespace SG::DataStructure::FEM;

/**
 * @brief 获取一号自由度集
 *
 * 返回一号自由度集的引用。
 *
 * @return 一号自由度集的引用
 */
DOFDirections FEM::RRODData::GetDOF1 () const
{
    auto dofs = Int2VDofSet (m_DOF1);
    if (dofs.empty())
    {
        return DOFDirections::DOF_Unknow;
    }
    return dofs[0];
}
void FEM::RRODData::SetDOF1 (const SG::DataStructure::FEM::DofSet& dofs)
{
    m_DOF1 = DofSet2Int (dofs);
}

/**
 * @brief 获取二号自由度集
 *
 * 返回二号自由度集的引用。
 *
 * @return 二号自由度集的引用
 */
DOFDirections FEM::RRODData::GetDOF2 () const
{
    auto dofs = Int2VDofSet (m_DOF2);
    return dofs[0];
}

void FEM::RRODData::SetDOF2 (const SG::DataStructure::FEM::DofSet& dofs)
{
    m_DOF2 = DofSet2Int (dofs);
}

/// @brief 判断两个RRODData是否相等
/// @param a
/// @param b
/// @return
bool SG::DataStructure::FEM::operator== (const RRODData& a, const RRODData& b)
{
    if (a.m_id != b.m_id)
    {
        return false;
    }
    if (a.m_G1 != b.m_G1)
    {
        return false;
    }
    if (a.m_G2 != b.m_G2)
    {
        return false;
    }
    if (a.m_DOF1 != b.m_DOF1)
    {
        return false;
    }
    if (a.m_DOF2 != b.m_DOF2)
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_alpha, b.m_alpha))
    {
        return false;
    }
    if (!SG::DataStructure::Common::isNear (a.m_refTemperature, b.m_refTemperature))
    {
        return false;
    }
    if (a.m_domainId != b.m_domainId)
    {
        return false;
    }
    return true;
}